<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateOrdersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('orders', function (Blueprint $table) {
            $table->id();
            $table->string('name', 20)->index()->comment("年月日-时分秒");
            $table->float('amount', 8, 2)->default(0)->comment('订单总金额');
            $table->float('discount', 6, 4)->default(0)->comment('订单折扣');
            $table->float('pay', 8, 2)->default(0)->comment('实付金额');
            $table->enum('way', ['wepay', 'alipay', 'cash'])->default('wepay')->comment('付款方式：微信,支付宝,现金');
            $table->enum('status', ['paid', 'nopay', 'debt'])->default('nopay')->comment("'已付','未付','欠账'");
            $table->foreignId('desk_id')->nullable()->constrained('desks')->onDelete('SET NULL')->comment('所属桌号');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('orders');
    }
}
